<template>
	<view class="page">
		<view class="header">
			<image :src="appLogo" mode=""></image>
			<view>
				<view>
					{{appName}}
				</view>
				<view>
					{{appDes}}
				</view>
			</view>
		</view>
		<view class="bg">

		</view>
		<view class="content">
			<image src="/static/download/bjdemo.png" style="z-index: 5;left: 50rpx;" mode="widthFix"></image>
			<image src="/static/download/bjdemo1.png" style="z-index: 4;left: 280rpx;top: 50rpx;width: 300rpx;"
				mode="widthFix"></image>
			<image src="/static/download/bjdem2.png" style="z-index: 3;left: 450rpx;width: 250rpx;top: 80rpx;"
				mode="widthFix"></image>
		</view>
		<view class="btns">
			<view  @click="down('and')">
				<view class="icon">
					<image src="/static/download/and.png" mode=""></image>
				</view>
				<view class="text">
					<view>Andriod版</view>
					<view>免费下载</view>
				</view>
			</view>
			<!-- <view v-if="isAndroid" @click="startApp">
				<view class="icon">
					<image src="/static/download/and.png" mode=""></image>
				</view>
				<view class="text">
					<view>打开APP</view>
				</view>
			</view> -->
			<view v-if="isIOS"  @click="navTo('/pages/index/ios-guidance/ios-guidance')">
				<view class="icon">
					<image src="/static/download/ios.png" mode=""></image>
				</view>
				<view class="text">
					<view>ios版</view>
					<view>免费下载</view>
				</view>
			</view>
		</view>
		<view class="wx" v-if="weixin">

		</view>
	</view>
</template>

<script>
	var u = navigator.userAgent
	export default {
		data() {
			return {
				appLogo: '/static/icon/LOGO.png', //app logo图片路径
				appName: '云赚', //app名称
				appDes: '免费领取环保袋', //app简述
				andHref: 'https://lmcoreoss.oss-cn-hangzhou.aliyuncs.com/yunZhuan.apk', //安卓app下载地址
				iosHref: 'https://itunes.apple.com/cn/app/hello-uni-app/id1417078253?mt=8', //苹果appStore链接
				weixin: false, //是否为微信内浏览器打开
				scheme: '' ,//scheme地址 如果已安装app直接打开，置空则不执行
				isIOS:false,
				isAndroid:false
			}
		},
		onLoad() {
			// 动态设置页面标题
			this.setTitle()
			// 判断该页面是否为微信内置浏览器内打开 true>显示浏览器内打开引导
			this.isWX()
			// 如果需要通过scheme直接打开app
			this.openApp()
			if (uni.getStorageSync(this.$util.APP_VERSION)) {
				let url = uni.getStorageSync(this.$util.APP_VERSION);
				this.versionApp = url
			}
			this.getDownload();
			this.isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;
			this.isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
			this.startApp();
			console.log("系统信息",uni.getSystemInfoSync())
			var lastTouchEnd = 0;
			document.documentElement.addEventListener('touchend', function (event) {
			  var now = Date.now();
			  if (now - lastTouchEnd <= 300) {
				event.preventDefault();
			  }
			  lastTouchEnd = now;
			}, false);
		},
		methods: {
			navTo(url){
				uni.navigateTo({
					url:url
				})
			},
			startApp() {
				let that = this;
				//android端
				if (this.isAndroid) {
					//安卓app的scheme协议
					window.location.href = 'yunzhuanApp://';
					// setTimeout(function() {
					// 	let hidden = window.document.hidden || window.document.mozHidden || window.document
					// 		.msHidden || window.document.webkitHidden
					// 	if (typeof hidden == "undefined" || hidden == false) {
					// 		//App store下载地址
					// 		uni.showModal({
					// 		    title: '提示',
					// 		    content: '你还未安装云赚APP，是否安装云赚APP',
					// 			confirmText:"是",
					// 		    success: function (res) {
					// 		        if (res.confirm) {
					// 		            that.down('and')
					// 		        } else if (res.cancel) {
					// 		            console.log('用户点击取消');
					// 		        }
					// 		    }
					// 		});
					// 	}
					// }, 2000);
				}
				// ios端
				// if (this.isIOS) {
				// 	//ios的scheme协议
				// 	window.location.href = 'yunzhuanApp://'
				// 	// setTimeout(function() {
				// 	// 	let hidden = window.document.hidden || window.document.mozHidden || window.document
				// 	// 		.msHidden || window.document.webkitHidden
				// 	// 	if (typeof hidden == "undefined" || hidden == false) {
				// 	// 		//App store下载地址
				// 	// 		window.location.href = "http://itunes.apple.com/app/id387682726";
				// 	// 	}
				// 	// }, 2000);
				// }
			},
			getDownload() {
				let httpData = {
					vn: 0
				}
				this.$util.doPostForm("/version/versionNumber", httpData, {}, false).then(res => {
					/* res的数据说明
					 * | 参数名称        | 一定返回     | 类型        | 描述
					 * | -------------|--------- | --------- | ------------- |
					 * | versionCode     | y        | int       | 版本号        |
					 * | versionName     | y        | String    | 版本名称      |
					 * | downloadUrl     | y        | String    | 版本下载链接（IOS安装包更新请放跳转store应用商店链接,安卓apk和wgt文件放文件下载链接）  |
					 */
					if (res.data.code == this.$ResponseStatus.OK) {
						// 兼容之前的版本（updateType是新版才有的参数）
						this.versionApp = res.data.data
					} else {}
				});
			},
			setTitle() {
				uni.setNavigationBarTitle({
					title: this.appName + '下载'
				});
			},
			isWX() {
				let ua = navigator.userAgent.toLowerCase();
				if (ua.match(/MicroMessenger/i) == "micromessenger") {
					this.weixin = true
				} else {
					this.weixin = false
				}
			},
			openApp() {
				if (this.scheme) {
					window.location = this.scheme
				}
			},
			down(type) {
				if (type == 'and') {
					window.location.href = this.versionApp.downloadUrl || this.andHref;
					// if(this.$environment === 'dev'){
					// 	window.location.href = this.andHref;
					// }
					this.$util.doPostForm("/report/download", {}, {}, false)
				} else {
					window.open(this.iosHref);
				}
			}
		}
	}
</script>

<style lang="less">
	@BgColor: #0079ff; //主题背景色

	.page {
		background-color: #f8f8f8;
		width: 100vw;
		height: 100vh;
		overflow: hidden;

		.header {
			width: 100vw;
			height: 250upx;
			background-color: @BgColor;
			padding-top: 110upx;
			display: flex;
			justify-content: center;

			image {
				width: 120upx;
				height: 120upx;
				margin-right: 30upx;
			}

			>view {
				height: 120upx;
				color: #fff;
				font-weight: 700;
				display: flex;
				flex-direction: column;
				justify-content: center;

				view:nth-child(1) {
					font-size: 34upx;
				}

				view:nth-child(2) {
					font-size: 28upx;
				}
			}
		}

		.bg {
			width: 100vw;
			height: 210upx;
			background-image: url('~@/static/download/bg.png');
			background-size: 100%;
			background-position: center bottom;
			background-repeat: no-repeat;
			position: absolute;
			left: 0;
			top: 200upx;
		}

		.content {
			width: 100%;
			position: relative;
			top: -70rpx;

			image {
				width: 350upx;
				// height: 750upx;
				position: absolute;
				top: 10rpx;
			}
		}

		.wx {
			position: fixed;
			z-index: 1000;
			left: 0;
			top: 0;
			background-color: rgba(0, 0, 0, .7);
			width: 100vw;
			height: 100vh;
			background-image: url('~@/static/download/wx.png');
			background-size: 100%;
			background-position: center 100upx;
			background-repeat: no-repeat;
		}
	}

	.btns {
		width: 100vw;
		position: fixed;
		z-index: 100;
		bottom: 10rpx;

		>view {
			width: 380upx;
			height: 120upx;
			background-color: @BgColor;
			color: #FFFFFF;
			display: flex;
			margin: 0 auto;
			margin-bottom: 40upx;
			border-radius: 15upx;
			box-shadow: 0 10upx 24upx -10upx @BgColor;
			;

			.icon {
				width: 120upx;
				height: 120upx;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.text {
				display: flex;
				flex-direction: column;
				justify-content: center;

				view:nth-child(1) {
					font-size: 34upx;
				}

				view:nth-child(2) {
					font-size: 28upx;
				}
			}

			image {
				width: 50upx;
				height: 50upx;
			}
		}

		>view:nth-child(2) {
			margin-bottom: 0upx;
		}
	}
</style>
